

import  wx

LOG_TEXTCTRL = 30001

class LogTextCtrl:
  
  class __Log:
    def WriteText(self, text):
      #print text
      
      if text[-1:] == '\n':
          text = text[:-1]
      textctrl = wx.FindWindowById(LOG_TEXTCTRL)
      textctrl.AppendText(text+"\n")
      
    write = WriteText  # why do this?  log.write
  
  instance = None

  def __init__(self):
    if not LogTextCtrl.instance:
      LogTextCtrl.instance =LogTextCtrl.__Log()            
    else:
      pass
    #print Log.instance

  def __getattr__(self, name):
    return getattr(self.instance, name)      


def test():
  log = LogTextCtrl()
  log.write('test')
  alog = LogTextCtrl()
  alog.write('a log')
  log.write('haha')
 


if __name__ == "__main__":
    test()
